interface List {
  readonly id: number,
  name: string,
  age?: number
}
interface Result {
  data: List[]
}

function render(result: Result) {
  result.data.forEach(item => {
    // console.log(item.id, item.name);
    if(item.age) {
      // console.log(item.age);
    }
  })
}

let result = {
  data: [
    {id: 1, name: 'A'},
    {id: 2, name: 'B', age: 15}
  ]
}
render(result)
interface StringArray {
  [index: number]: string,

}
let char: StringArray = ['A', 'B']

interface Names {
  [x: string]: any
  // y: number
  [z: number]: string
}
let names: Names = ['nameA', 'nameB']

// console.log(names['1']);
// let add: (x: number, y: number) => number
// interface Add {
//   (x: number, y: number): number
// }
type Add =(x: number, y:number) => number
let myAdd: Add = (a, b) => a + b

interface Lib {
  (): void,
  version: string,
  doSomething(): void
}

function getLib() {
  let lib: Lib =(() => {}) as Lib
  lib.version = '1.0'
  lib.doSomething = () => {}
  return lib
}
let lib1 = getLib()
lib1()
lib1.doSomething()
